package com.example.component.Window.listeners;

import com.example.component.Window.FunFusionMenuBar;
import com.example.login.ILoginService;
import com.example.service.IService;
import com.example.service.ServiceManager;
import com.vaadin.Application;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.TabSheet.SelectedTabChangeEvent;
import com.vaadin.ui.TabSheet.SelectedTabChangeListener;

public class HomeWindowListerers implements ClickListener, ValueChangeListener, SelectedTabChangeListener {

	private Application app;
	
	public HomeWindowListerers(Application app) {
		this.app = app;
	}
	
	public void buttonClick(ClickEvent event) {
		// TODO Auto-generated method stub
		System.out.println("buttonClicked");
	}

	public void valueChange(ValueChangeEvent event) {
		// TODO Auto-generated method stub
		Property p = event.getProperty();
		FunFusionMenuBar.Type selectedMenuName = (FunFusionMenuBar.Type) p
				.getValue();
		Class c = p.getType();
		switch (selectedMenuName) {
		case SYSTEMUSER: {
			System.out.println("You have selected System User menu");
			break;
		}
		case EVENTUSERS: {
			System.out.println("You have selected Event User menu");
			break;
		}
		case LOGOUT: {
			System.out.println("You have selected logout option");
			doLogOut();
			break;
		}
		case CURRENTEVENTS: {
			System.out.println("You have selected Current Events menu");
			break;
		}
		case PASTEVENTS: {
			System.out.println("You have selected Past Events menu");
			break;
		}
		case FINANCE: {
			System.out.println("You have selected Finance menu");
			break;
		}
		case LOGINASANOTHERUSER: {
			System.out.println("You have selected to logout and login as a different User");
			break;
		}
		}
	}

	private void doLogOut() {
		ILoginService loginService = (ILoginService) ServiceManager.getInstance().getService(IService.LOGINSERVICE);
		loginService.logout(this.app, false);
	}

	public void selectedTabChange(SelectedTabChangeEvent event) {
		// TODO Auto-generated method stub
		System.out.println("Tab Selection Changed");
	}

}
